#ifndef ROSTOPIC_H
#define ROSTOPIC_H

#include <QThread>
#include <QTime>

#include <ros/ros.h>
#include <nav_msgs/Odometry.h>
#include <tf/transform_datatypes.h>

#include <sensor_msgs/BatteryState.h>


class ROSTopic : public QThread
{
    #define   PI          3.1415926
    Q_OBJECT
    Q_PROPERTY(int timeStamp READ timeStamp WRITE setTimeStamp NOTIFY timeStampChanged)
    Q_PROPERTY(double frequency READ frequency WRITE setFrequency NOTIFY frequencyChanged)
    Q_PROPERTY(double positionX READ positionX WRITE setPositionX NOTIFY positionXChanged)
    Q_PROPERTY(double positionY READ positionY WRITE setPositionY NOTIFY positionYChanged)
    Q_PROPERTY(double yaw READ yaw WRITE setYaw NOTIFY yawChanged)
    Q_PROPERTY(double linearX READ linearX WRITE setLinearX NOTIFY linearXChanged)
    Q_PROPERTY(double angularZ READ angularZ WRITE setAngularZ NOTIFY angularZChanged)
    Q_PROPERTY(double angularX READ angularX WRITE setAngularX NOTIFY angularXChanged)  //自定义为角度传感器的数据
    Q_PROPERTY(int leftrmp READ leftrmp WRITE setLeftrmp NOTIFY leftrmpChanged)
    Q_PROPERTY(int rightrmp READ rightrmp WRITE setRightrmp NOTIFY rightrmpChanged)
    Q_PROPERTY(double voltage READ voltage WRITE setVoltage NOTIFY voltageChanged)
    Q_PROPERTY(double current READ current WRITE setCurrent NOTIFY currentChanged)
    Q_PROPERTY(double charge READ charge WRITE setCharge NOTIFY chargeChanged)
    Q_PROPERTY(double capacity READ capacity WRITE setCapacity NOTIFY capacityChanged)
    Q_PROPERTY(double designCapacity READ designCapacity WRITE setDesignCapacity NOTIFY designCapacityChanged)
    Q_PROPERTY(double percentage READ percentage WRITE setPercentage NOTIFY percentageChanged)

public:
    explicit ROSTopic(int argc, char *argv[]);
    void run();

    int timeStamp() { return _timeStamp; }
    double frequency() { return _frequency; }
    double positionX() { return _positionX; }
    double positionY() { return _positionY; }
    double yaw() { return _yaw; }
    double linearX() { return _linearX; }
    double angularZ() { return _angularZ; }
    double angularX() { return _angularX; }
    int leftrmp() { return _leftrmp; }
    int rightrmp() { return _rightrmp; }
    double voltage() { return _voltage; }
    double current() { return _current; }
    double charge() { return _charge; }
    double capacity() { return _capacity; }
    double designCapacity() { return _designCapacity; }
    double percentage() { return _percentage; }


    void setTimeStamp(int timeStamp_);
    void setFrequency(double frequency_);
    void setPositionX(double positionX_);
    void setPositionY(double positionY_);
    void setYaw(double yaw_);
    void setLinearX(double linearX_);
    void setAngularZ(double angularZ_);
    void setAngularX(double angularZ_);
    void setLeftrmp(int leftrmp_);
    void setRightrmp(int rightrmp_);
    void setVoltage(double voltage_);
    void setCurrent(double current_);
    void setCharge(double charge_);
    void setCapacity(double capacity_);
    void setDesignCapacity(double designCapacity_);
    void setPercentage(double percentage_);

signals:
    void timeStampChanged();
    void frequencyChanged();
    void positionXChanged();
    void positionYChanged();
    void yawChanged();
    void linearXChanged();
    void angularZChanged();
    void angularXChanged();
    void leftrmpChanged();
    void rightrmpChanged();
    void voltageChanged();
    void currentChanged();
    void chargeChanged();
    void capacityChanged();
    void designCapacityChanged();
    void percentageChanged();

public slots:

private:
    void odomCallback(const nav_msgs::Odometry::ConstPtr& odom);
    void batteryCallback(const sensor_msgs::BatteryState::ConstPtr& battery);

private:
    int _argc;
    char **_argv;

    double _wheel_separation;
    double _wheel_radius;
    double _reduction;
    QTime _lastTime;

    int _timeStamp;
    double _frequency;
    double _positionX = 0;
    double _positionY = 0;
    double _yaw = 0;
    double _linearX = 0;
    double _angularZ = 0;
    double _angularX = 0;
    int _leftrmp = 0;
    int _rightrmp = 0;
    double _voltage;
    double _current;
    double _charge;
    double _capacity;
    double _designCapacity;
    double _percentage;
};

#endif // ROSTOPIC_H
